package com.qzsoft.zhjd.exp.modules.stressmachine.service.impl;

import java.util.Map;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qzsoft.zhjd.common.components.BaseServiceComponent;
import com.qzsoft.zhjd.exp.modules.stressmachine.entity.StressMachineEntity;
import com.qzsoft.zhjd.exp.modules.stressmachine.mapper.StressMachineMapper;
import com.qzsoft.zhjd.exp.modules.stressmachine.service.StressMachineService;

/**
 * @ClassName: StressMachineServiceImpl
 * @Description: 压力机业务接口实现
 * @author linhuawei
 * @since 2021-04-20
 */
@Service
public class StressMachineServiceImpl extends ServiceImpl<StressMachineMapper, StressMachineEntity>
        implements StressMachineService {

    @Autowired
    private BaseServiceComponent baseServiceComponent;

    @Override
    public IPage<StressMachineEntity> page(Map<String, Object> params) {
        // 查询条件
        QueryWrapper<StressMachineEntity> queryWrapper = new QueryWrapper<>();
        if (ObjectUtils.isNotEmpty(params.get("baseName"))) {
            queryWrapper.like("base_name", params.get("baseName"));
        }
        if (ObjectUtils.isNotEmpty(params.get("testType"))) {
            queryWrapper.like("test_type", params.get("testType"));
        }
        if (ObjectUtils.isNotEmpty(params.get("cubeCode"))) {
            queryWrapper.like("cube_code", params.get("cubeCode"));
        }
        if (null != params.get("startTime")) {
            queryWrapper.ge("DATE_FORMAT(test_date,'%Y-%m-%d')", params.get("startTime"));
        }
        if (null != params.get("endTime")) {
            queryWrapper.le("DATE_FORMAT(test_date,'%Y-%m-%d')", params.get("endTime"));
        }
        queryWrapper.orderByDesc("cube_code", "test_type");

        // 执行查询操作
        IPage<StressMachineEntity> page = baseServiceComponent.getPage(params, StressMachineEntity.class);
        return baseMapper.selectPage(page, queryWrapper);
    }


}
